import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-10-28
 * Time: 23:30
 */
public class StockSpanner {
    Stack<int[]> stack;
    int index;
    public StockSpanner() {
        this.stack=new Stack<>();
        stack.push(new int[]{-1,Integer.MAX_VALUE});
    }

    public int next(int price) {
        while(!stack.isEmpty()){
            if(price>=stack.peek()[1]){
                stack.pop();
            }else{
                break;
            }
        }
        int ret=index-stack.peek()[0];
        stack.push(new int[]{index,price});
        index++;
        return ret;
    }
}
